package com.simen.connectandroid.command;

import com.simen.connectandroid.command.utils.CommandCreator;
import com.simen.connectandroid.model.Device;
import com.simen.hellobytes.log.Log;
import com.simen.hellobytes.runtime.RuntimeHelper;

/**
 * 获取名称、型号、品牌、系统版本等继承信息
 * Created on 2021/10/30 15:21.
 *
 * @author Simen
 */
public abstract class InfoCommand extends AdbCommand<InfoCommand> {

    private static final String TAG = InfoCommand.class.getSimpleName();

    private boolean execResult = false;
    protected String result;

    public InfoCommand(Device device) {
        super(device);
    }

    @Override
    public InfoCommand exec() {
        RuntimeHelper runtimeHelper = RuntimeHelper.create(CommandCreator.createAdb()
                .appendAdbDevice(device)
                .appendParam("shell getprop", getProduct())
                .build());
        runtimeHelper.exec();

        execResult = runtimeHelper.getProcessCode() == 0;
        log = runtimeHelper.getOutputLog();

        Log.i(TAG, runtimeHelper.command() + ": " + execResult);
        Log.i(TAG, log);

        if (execResult) {
            result = log.trim();
        }

        return this;
    }

    @Override
    public boolean execResult() {
        return execResult;
    }

    public String getResult() {
        return result;
    }

    public abstract String getProduct();
}
